<?php echo $javascript->link('filter_actions'); ?>
<div class="jobs index">
    <a href="" class="filtro_a" onclick="show_filter(); return false;"><?php echo __('Filtro', true); ?></a>
    <input type="hidden" id="input_filtro" value="0">
    <div id="filtro_busqueda" class="filtro" style="display: block;">
        <fieldset>
            <?php echo $form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'emails'))); ?>
            <div class="date_range">
                <label>Rango de Fechas</label>
                <?php
                echo $form->input('date_from', array('label' => false));
                ?>
                <span>-</span>
                <?php
                echo $form->input('date_to', array('label' => false));
                ?>
                <span><?php echo $this->Html->link(__('Hoy', true), array(), array('onclick' => 'fecha_hoy(); return false;')); ?></span>
                &nbsp;&nbsp;&nbsp;
                <span><?php echo $this->Html->link(__('Últimos 7 Días', true), array(), array('onclick' => 'fecha_semana(); return false;')); ?></span>
                <?php
                echo $form->input('hidden_actual_date', array('type' => 'hidden', 'value' => date('d/m/Y')));
                echo $form->input('hidden_week_date', array('type' => 'hidden', 'value' => date('d/m/Y', strtotime('-7 day', strtotime(date('Y-m-d H:i:s'))))));
                ?>
            </div>
            <?php
            echo $form->submit(__('Filtrar', true));
            echo $form->end();
            ?>
        </fieldset>
    </div>
    <h2 class="left"><?php __('Emails'); ?></h2>
    <div class="clear"></div>
    <p><b>Cantidad de Emails <?php echo count($jobs);?></b></p>
    <table cellpadding="0" cellspacing="0" class="table_jobs">
        <tr>
            <th><?php echo __('Nombre', true); ?></th>
            <th><?php echo __('Email', true); ?></th>
        </tr>
        <?php
        if (empty($jobs)) {
            ?>
        <tr>
            <td colspan="2">No se encontraron emails</td>
        </tr>
            <?php
        }

        $i = 0;
        $emails = array();
        foreach ($jobs as $job):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            $emails[$job['Job']['email']] = $job['Job']['email'];
            ?>
        <tr<?php echo $class; ?>>
            <td><?php echo $job['Job']['contact_name']?></td>
            <td><?php echo $job['Job']['email']?></td>
        </tr>
        <?php endforeach; ?>
    </table>
    <br />
    <b>Separados por comas</b>
    <br />
    <br />
    <?php 
    //ahora muestro los emails pero separados por coma
    $mostrar_emails = implode(', ', $emails);
    echo $mostrar_emails;
    ?>
</div>
<script type="text/javascript" >

    (function($){
        // Date picker
        $("#JobDateFrom").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        // Date picker
        $("#JobDateTo").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });

    })(jQuery);

    function fecha_hoy(){
        var hoy = $('#JobHiddenActualDate').val();
        $('#JobDateFrom').val(hoy);
        $('#JobDateTo').val(hoy);
        $('#JobIndexForm').submit();
    }

    function fecha_semana(){
        var hoy = $('#JobHiddenActualDate').val();
        var semana = $('#JobHiddenWeekDate').val();
        $('#JobDateFrom').val(semana);
        $('#JobDateTo').val(hoy);
        $('#JobIndexForm').submit();
    }
</script>